<?php

Yii::import('application.models._base.BaseOrders');

class UserOrder extends BaseOrders {
	public $allStatus = array(
		'1' => 'unpaid',
		'5' => 'paid but not shipped',
		'6' => 'shipped',
		'7' => 'on hold',
		'8' => 'success',
		'9' => 'cancelled',
        '10'=> 'processing'
	);
	
	public $allType = array('1'=>'N','2'=>'Y');
	
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}
	
	/**
	 * (non-PHPdoc)
	 * @see BaseAuctions::relations()
	 */
	public function relations(){
		return CMap::mergeArray(parent::relations(), array(
		));
	}
	
	public function getStatusName(){
		return empty($this->status) ? '' : $this->allStatus[$this->status];
	}
	
	public function getTypeName(){
		return empty($this->allType) ? '' : $this->allType[$this->type];
	}
	public function getVendor(){

		if($this->vendor_id!=0){
			$vonder=Vendors::model()->findByPk($this->vendor_id);
			return $vonder->company_name;
		}else{
			return "";
		}	
	}
	public function search($order_id=null) {
		$criteria = new CDbCriteria;
		//$criteria->addInCondition('t.status',array(5,6,7,8,10));
		if(!empty($order_id)){
		$criteria->compare('t.id', $order_id);
		}
		$criteria->compare('t.customer_id', $this->customer_id);
		$criteria->addNotInCondition('status', array(1));
		$criteria->order = 't.created desc';
		return new CActiveDataProvider($this, array(
			'criteria' => $criteria,
			'pagination'=>array(
       			'pageSize'=>20,
    		),
		));
	}
	
	
}

